﻿using System;
using System.Configuration;
using System.IO;
using System.Management;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Hosting;
using Microsoft.Win32;

namespace WeiSha.Core
{
	// Token: 0x02000024 RID: 36
	public class Server
	{
		// Token: 0x1700006A RID: 106
		// (get) Token: 0x0600012F RID: 303 RVA: 0x00008DEC File Offset: 0x00006FEC
		public static string IP
		{
			get
			{
				bool flag = Server.Domain.Equals("localhost", StringComparison.CurrentCultureIgnoreCase);
				string text;
				if (flag)
				{
					text = "127.0.0.1";
				}
				else
				{
					HttpContext httpContext = HttpContext.Current;
					try
					{
						bool flag2 = httpContext != null && httpContext.Request != null && httpContext.Request.ServerVariables != null;
						if (flag2)
						{
							return HttpContext.Current.Request.ServerVariables.Get("Local_Addr").ToString();
						}
					}
					catch
					{
					}
					IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
					bool flag3 = hostEntry == null;
					if (flag3)
					{
						text = "";
					}
					else
					{
						bool flag4 = hostEntry.AddressList.Length < 1;
						if (flag4)
						{
							text = "";
						}
						else
						{
							try
							{
								IPAddress ipaddress = hostEntry.AddressList[1];
								text = ipaddress.ToString().Trim();
							}
							catch
							{
								text = "";
							}
						}
					}
				}
				return text;
			}
		}

		// Token: 0x1700006B RID: 107
		// (get) Token: 0x06000130 RID: 304 RVA: 0x00008EE4 File Offset: 0x000070E4
		public static bool IsLocalIP
		{
			get
			{
				string ip = Server.IP;
				bool flag = ip == "127.0.0.1";
				bool flag2;
				if (flag)
				{
					flag2 = true;
				}
				else
				{
					bool flag3 = Server.Domain.ToLower().Trim() == "localhost";
					flag2 = flag3;
				}
				return flag2;
			}
		}

		// Token: 0x1700006C RID: 108
		// (get) Token: 0x06000131 RID: 305 RVA: 0x00008F34 File Offset: 0x00007134
		public static bool IsIntranetIP
		{
			get
			{
				bool isLocalIP = Server.IsLocalIP;
				bool flag;
				if (isLocalIP)
				{
					flag = true;
				}
				else
				{
					string ip = Server.IP;
					bool flag2 = ip.Substring(0, 3) == "10." || ip.Substring(0, 7) == "192.168" || ip.Substring(0, 7) == "172.16.";
					flag = flag2;
				}
				return flag;
			}
		}

		// Token: 0x1700006D RID: 109
		// (get) Token: 0x06000132 RID: 306 RVA: 0x00008FA0 File Offset: 0x000071A0
		public static string Port
		{
			get
			{
				string text = "80";
				string text2;
				try
				{
					bool flag = HttpContext.Current != null;
					if (flag)
					{
						text = HttpContext.Current.Request.Url.Port.ToString();
					}
					bool flag2 = text == "443";
					if (flag2)
					{
						text = "80";
					}
					text2 = text;
				}
				catch
				{
					text2 = text;
				}
				return text2;
			}
		}

		// Token: 0x1700006E RID: 110
		// (get) Token: 0x06000133 RID: 307 RVA: 0x00009014 File Offset: 0x00007214
		public static string Domain
		{
			get
			{
				try
				{
					bool flag = HttpContext.Current != null;
					if (flag)
					{
						return HttpContext.Current.Request.Url.Host.ToString();
					}
				}
				catch
				{
					return "";
				}
				return "";
			}
		}

		// Token: 0x1700006F RID: 111
		// (get) Token: 0x06000134 RID: 308 RVA: 0x00009074 File Offset: 0x00007274
		public static string DomainPath
		{
			get
			{
				string text = string.Empty;
				bool flag = HttpContext.Current != null;
				if (flag)
				{
					text = "http://" + Server.Domain + ":" + Server.Port;
				}
				return text;
			}
		}

		// Token: 0x17000070 RID: 112
		// (get) Token: 0x06000135 RID: 309 RVA: 0x000090B8 File Offset: 0x000072B8
		public static string RootDomain
		{
			get
			{
				string domain = Server.Domain;
				string mainName = Server.MainName;
				bool flag = domain.Length < mainName.Length;
				string text;
				if (flag)
				{
					text = string.Empty;
				}
				else
				{
					text = "";
				}
				return text;
			}
		}

		// Token: 0x17000071 RID: 113
		// (get) Token: 0x06000136 RID: 310 RVA: 0x000090F8 File Offset: 0x000072F8
		public static string MainName
		{
			get
			{
				ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings[ConfigurationManager.ConnectionStrings.Count - 1];
				return connectionStringSettings.Name;
			}
		}

		// Token: 0x17000072 RID: 114
		// (get) Token: 0x06000137 RID: 311 RVA: 0x00009128 File Offset: 0x00007328
		public static string OS
		{
			get
			{
				OperatingSystem osversion = Environment.OSVersion;
				PlatformID platform = osversion.Platform;
				PlatformID platformID = platform;
				if (platformID != PlatformID.Win32Windows)
				{
					if (platformID == PlatformID.Win32NT)
					{
						switch (osversion.Version.Major)
						{
						case 3:
							return "WindNT 3.51 ";
						case 4:
							return "WinNT 4.0 ";
						case 5:
							switch (osversion.Version.Minor)
							{
							case 0:
								return "Win2000";
							case 1:
								return "WinXP ";
							case 2:
								return "Win2003 ";
							}
							break;
						case 6:
						{
							int minor = osversion.Version.Minor;
							int num = minor;
							if (num == 0)
							{
								return "WinVista ";
							}
							if (num == 1)
							{
								return "Win7 ";
							}
							break;
						}
						}
					}
				}
				else
				{
					int minor2 = osversion.Version.Minor;
					int num2 = minor2;
					if (num2 == 0)
					{
						return "Win95 ";
					}
					if (num2 != 10)
					{
						if (num2 == 90)
						{
							return "WinMe ";
						}
					}
					else
					{
						bool flag = osversion.Version.Revision.ToString() == "2222A ";
						if (flag)
						{
							return "Win98r2";
						}
						return "Win98 ";
					}
				}
				return osversion.VersionString;
			}
		}

		// Token: 0x17000073 RID: 115
		// (get) Token: 0x06000138 RID: 312 RVA: 0x000092A0 File Offset: 0x000074A0
		public static string IISVersion
		{
			get
			{
				string text = string.Empty;
				RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("software\\microsoft\\inetstp");
				bool flag = registryKey != null;
				if (flag)
				{
					text = Convert.ToInt32(registryKey.GetValue("majorversion", -1)).ToString();
				}
				return text;
			}
		}

		// Token: 0x17000074 RID: 116
		// (get) Token: 0x06000139 RID: 313 RVA: 0x000092F4 File Offset: 0x000074F4
		public static int CPUCount
		{
			get
			{
				int num;
				try
				{
					string environmentVariable = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
					num = (int)Convert.ToInt16(environmentVariable);
				}
				catch
				{
					num = 0;
				}
				return num;
			}
		}

		// Token: 0x17000075 RID: 117
		// (get) Token: 0x0600013A RID: 314 RVA: 0x00009330 File Offset: 0x00007530
		public static string CPUHz
		{
			get
			{
				string text2;
				try
				{
					ManagementClass managementClass = new ManagementClass("Win32_Processor");
					ManagementObjectCollection instances = managementClass.GetInstances();
					int count = instances.Count;
					ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
					string text = "";
					foreach (ManagementBaseObject managementBaseObject in managementObjectSearcher.Get())
					{
						ManagementObject managementObject = (ManagementObject)managementBaseObject;
						text = managementObject.Properties["CurrentClockSpeed"].Value.ToString();
					}
					double num = Convert.ToDouble(text);
					text2 = (Math.Round(num / 100.0) / 10.0).ToString();
				}
				catch
				{
					text2 = "";
				}
				return text2;
			}
		}

		// Token: 0x17000076 RID: 118
		// (get) Token: 0x0600013B RID: 315 RVA: 0x0000941C File Offset: 0x0000761C
		public static double RamSize
		{
			get
			{
				double num2;
				try
				{
					double num = 0.0;
					ManagementClass managementClass = new ManagementClass("Win32_PhysicalMemory");
					ManagementObjectCollection instances = managementClass.GetInstances();
					foreach (ManagementBaseObject managementBaseObject in instances)
					{
						ManagementObject managementObject = (ManagementObject)managementBaseObject;
						num += Math.Round((double)(long.Parse(managementObject.Properties["Capacity"].Value.ToString()) / 1024L / 1024L) / 1024.0, 1);
					}
					instances.Dispose();
					managementClass.Dispose();
					num2 = num;
				}
				catch
				{
					num2 = 0.0;
				}
				return num2;
			}
		}

		// Token: 0x17000077 RID: 119
		// (get) Token: 0x0600013C RID: 316 RVA: 0x00009508 File Offset: 0x00007708
		public static string DotNetVersion
		{
			get
			{
				string text = Environment.Version.ToString();
				bool flag = text.IndexOf('.') < 0;
				string text2;
				if (flag)
				{
					text2 = text;
				}
				else
				{
					text = text.Substring(0, 3);
					text2 = text;
				}
				return text2;
			}
		}

		// Token: 0x17000078 RID: 120
		// (get) Token: 0x0600013D RID: 317 RVA: 0x00009544 File Offset: 0x00007744
		public static string CPU_ID
		{
			get
			{
				string text = null;
				try
				{
					ManagementClass managementClass = new ManagementClass("win32_Processor");
					ManagementObjectCollection instances = managementClass.GetInstances();
					foreach (ManagementBaseObject managementBaseObject in instances)
					{
						ManagementObject managementObject = (ManagementObject)managementBaseObject;
						bool flag = managementObject.Properties["Processorid"] != null;
						if (flag)
						{
							text = managementObject.Properties["Processorid"].Value.ToString();
							break;
						}
					}
				}
				catch
				{
				}
				bool flag2 = string.IsNullOrWhiteSpace(text);
				if (flag2)
				{
					text = "notGetCPU";
				}
				return text;
			}
		}

		// Token: 0x17000079 RID: 121
		// (get) Token: 0x0600013E RID: 318 RVA: 0x00009610 File Offset: 0x00007810
		public static string HardDiskID
		{
			get
			{
				string text = null;
				try
				{
					ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
					using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
					{
						if (enumerator.MoveNext())
						{
							ManagementObject managementObject = (ManagementObject)enumerator.Current;
							text = managementObject["SerialNumber"].ToString().Trim();
						}
					}
				}
				catch
				{
				}
				bool flag = string.IsNullOrWhiteSpace(text);
				if (flag)
				{
					try
					{
						ManagementObjectCollection managementObjectCollection = new ManagementObjectSearcher
						{
							Query = new SelectQuery("Win32_DiskDrive", "", new string[] { "PNPDeviceID", "Signature" })
						}.Get();
						ManagementObjectCollection.ManagementObjectEnumerator enumerator2 = managementObjectCollection.GetEnumerator();
						enumerator2.MoveNext();
						ManagementBaseObject managementBaseObject = enumerator2.Current;
						text = managementBaseObject.Properties["signature"].Value.ToString().Trim();
					}
					catch
					{
					}
				}
				bool flag2 = string.IsNullOrWhiteSpace(text);
				if (flag2)
				{
					try
					{
						ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
						ManagementObject managementObject2 = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
						managementObject2.Get();
						text = managementObject2.GetPropertyValue("VolumeSerialNumber").ToString();
					}
					catch
					{
					}
				}
				bool flag3 = string.IsNullOrWhiteSpace(text);
				if (flag3)
				{
					text = "notGetHardDiskID";
				}
				return text;
			}
		}

		// Token: 0x1700007A RID: 122
		// (get) Token: 0x0600013F RID: 319 RVA: 0x000097A8 File Offset: 0x000079A8
		public static string ProgramPath
		{
			get
			{
				return HostingEnvironment.ApplicationPhysicalPath;
			}
		}

		// Token: 0x06000140 RID: 320 RVA: 0x000097C0 File Offset: 0x000079C0
		public static string MapPath(string path)
		{
			bool flag = string.IsNullOrWhiteSpace(path);
			string text;
			if (flag)
			{
				text = path;
			}
			else
			{
				bool flag2 = path.IndexOf("?") > -1;
				if (flag2)
				{
					path = path.Substring(0, path.LastIndexOf("?"));
				}
				string text2 = "^[a-zA-Z]:\\\\{1,2}.+(\\\\?)$";
				bool flag3 = Regex.IsMatch(path, text2, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
				if (flag3)
				{
					path = path.Replace("/", "\\");
				}
				else
				{
					path = HostingEnvironment.MapPath(path);
				}
				bool flag4 = string.IsNullOrWhiteSpace(path);
				if (flag4)
				{
					text = path;
				}
				else
				{
					bool flag5 = path.IndexOf("\\") > -1;
					if (flag5)
					{
						bool flag6 = path.Substring(path.LastIndexOf("\\")).IndexOf(".") < 0;
						if (flag6)
						{
							bool flag7 = path.Substring(path.Length - 1) != "\\";
							if (flag7)
							{
								path += "\\";
							}
						}
					}
					path = Regex.Replace(path, "\\\\+", "\\");
					text = path;
				}
			}
			return text;
		}

		// Token: 0x06000141 RID: 321 RVA: 0x000098C8 File Offset: 0x00007AC8
		public static string VirtualPath(string path)
		{
			path = path.Replace("\\", "/");
			path = path.Replace("~/", HostingEnvironment.ApplicationVirtualPath);
			bool flag = path.IndexOf("/") > -1;
			if (flag)
			{
				bool flag2 = path.Substring(path.LastIndexOf("/")).IndexOf(".") < 0;
				if (flag2)
				{
					bool flag3 = path.Substring(path.Length - 1) != "/";
					if (flag3)
					{
						path += "/";
					}
				}
			}
			path = Regex.Replace(path, "\\/+", "/");
			return path;
		}

		// Token: 0x06000142 RID: 322 RVA: 0x00009970 File Offset: 0x00007B70
		public static string LegalName(string filename)
		{
			bool flag = filename.IndexOf("/") > -1;
			if (flag)
			{
				filename = filename.Substring(filename.LastIndexOf("/") + 1);
			}
			bool flag2 = filename.IndexOf("\\") > -1;
			if (flag2)
			{
				filename = filename.Substring(filename.LastIndexOf("\\") + 1);
			}
			string text = "\\/:*?<>|\"";
			string text2 = "＼／：★？〖〗｜＂";
			for (int i = 0; i < text.Length; i++)
			{
				filename = filename.Replace(text.Substring(i, 1), text2.Substring(i, 1));
			}
			return filename;
		}

		// Token: 0x06000143 RID: 323 RVA: 0x00009A14 File Offset: 0x00007C14
		public static string LegalPath(string path)
		{
			string text = ":*?<>|\"";
			string text2 = "：★？〖〗｜＂";
			for (int i = 0; i < text.Length; i++)
			{
				path = path.Replace(text.Substring(i, 1), text2.Substring(i, 1));
			}
			return path;
		}

		// Token: 0x06000144 RID: 324 RVA: 0x00009A64 File Offset: 0x00007C64
		public static void Rewriter(string path)
		{
			HttpContext httpContext = HttpContext.Current;
			httpContext.RewritePath(path);
		}

		// Token: 0x06000145 RID: 325 RVA: 0x00009A80 File Offset: 0x00007C80
		public static long getTime()
		{
			return Server.getTime(DateTime.Now);
		}

		// Token: 0x06000146 RID: 326 RVA: 0x00009A9C File Offset: 0x00007C9C
		public static long getTime(DateTime time)
		{
			DateTime dateTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
			return (long)(time - dateTime).TotalMilliseconds;
		}

		// Token: 0x1700007B RID: 123
		// (get) Token: 0x06000147 RID: 327 RVA: 0x00009AD8 File Offset: 0x00007CD8
		public static DateTime InitDateTime
		{
			get
			{
				bool flag = Server._initDate > DateTime.Now.AddYears(-100);
				DateTime dateTime;
				if (flag)
				{
					dateTime = Server._initDate;
				}
				else
				{
					DateTime deployTime = License.Value.DeployTime;
					DateTime initialDate = Database.InitialDate;
					DateTime dateTime2 = DateTime.Now;
					DirectoryInfo directoryInfo = new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath);
					foreach (DirectoryInfo directoryInfo2 in directoryInfo.GetDirectories())
					{
						bool flag2 = directoryInfo2.CreationTime < dateTime2;
						if (flag2)
						{
							dateTime2 = directoryInfo2.CreationTime;
						}
					}
					Server._initDate = ((deployTime < initialDate) ? deployTime : initialDate);
					Server._initDate = ((Server._initDate < dateTime2) ? Server._initDate : dateTime2);
					dateTime = Server._initDate;
				}
				return dateTime;
			}
		}

		// Token: 0x0400005A RID: 90
		private static DateTime _initDate = DateTime.Now.AddYears(-200);
	}
}
